﻿using System;
using System.Diagnostics;

namespace Sustainalytics.LongRunningTaskManager.Service
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            if (Environment.UserInteractive)
            {
                // start as console app
                ProgramConsole.Start();
            }
            else
            {
                // start as windows service
                ProgramWindowsService.Start();
            }
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
        {
            Exception e = (Exception)args.ExceptionObject;

            var p = Process.GetCurrentProcess().ProcessName;
            EventLog.WriteEntry(p, e.ToString());
            Console.WriteLine(e.ToString());

            throw e;         
        }
    }
}
